// Desc: 公共方法
import * as XLSX from "xlsx";

export const defaultMockMenu = [
    {
        code: 'home',
        name: '首页'
    },
    {
        code: 'cardList',
        name: '律师咨询'
    },
    {
        code: 'postManager',
        name: '法律论坛',
        children: [
            {
                name: '帖子列表',
                code: 'post',
            },
            {
                name: '帖子管理',
                code: 'postAdmin',
            },
        ]
    },
    {
        code: 'banner',
        name: 'Banner管理',
    },
    {
        code: 'notice',
        name: '公告管理',
    },
    {
        code: 'news',
        name: '新闻管理',
    },
    {
        code: 'question',
        name: '题库管理',
    },
    {
        code: 'answerManager',
        name: '答题管理',
        children: [
            {
                name: '答题',
                code: 'answer',
            },
            {
                name: '答题结果',
                code: 'answerResult',
            }
        ]
    },
    {
        code: 'userCenter',
        name: '个人中心',
        children: [
            {
                code: 'my',
                name: '个人中心',
            },
            {
                code: 'collect',
                name: '我的收藏'
            },
            {
                code: 'like',
                name: '我的点赞'
            },
        ]
    },
    {
        name: '用户管理',
        code: 'user-management',
        icon: 'img_3',
        activeIcon: 'img_3_active',
        children: [
            {
                name: '角色管理',
                code: 'role',
            },
            {
                name: '用户管理',
                code: 'user',
            }
        ]
    },
]

export const exportToExcel = (name,data = []) => {
    if (!name) {
        name = '导出文件'
    }
    if (!data) return
    // 创建一个工作簿
    const workbook = XLSX.utils.book_new();
    // 创建一个工作表
    const worksheet = XLSX.utils.aoa_to_sheet([
        ...data
    ]);

    // 将工作表添加到工作簿
    XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');

    // 生成Excel文件
    XLSX.writeFile(workbook, name + '.xlsx');
};
